package ar.com.ctrln.persistence.dao.insumo;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import ar.com.ctrln.persistence.dao.AbstractHibernateDao;
import ar.com.ctrln.persistence.model.insumo.Insumo;

@Repository("insumoDao")
public class HibernateInsumoDao extends AbstractHibernateDao<Insumo> implements InsumoDao {

	@Override
	public Insumo findInsumoById(long id) {
		Query q = getSession().createQuery("from Insumo a where a.id = ?");
		q.setParameter(0, id);
		return (Insumo) q.uniqueResult();
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Insumo> insumosByTipo(String tipo) {
		Query q = getSession().createQuery("from Insumo i where i.tipoInsumo = ?");
		q.setParameter(0, tipo);
		return (List<Insumo>)q.list();
	}

}
